<include file="Common:header"/>
<!--编辑器 --> 
<link type="text/css" rel="stylesheet" href="/Public/css/postkeyword.css" />
<link type="text/css" rel="stylesheet" href="/Public/css/keyword.css" />
<link type="text/css" rel="stylesheet" href="/Public/css/common.css" />
<script src="/Public/js/keyword.js"></script>
<!--主窗体-->
<div class="container app">
	<!--左侧菜单-->
	<include file="Common:sidebar" /> 
		<div id="mainCon" class="mainCon">
			<h4>新建图文回复</h4>
			<div class="bk10"></div>
		
			<form class="form-horizontal form "  action="" method="post" enctype="multipart/form-data" onsubmit="return postrule(this)" >
			
				<input type="hidden" name="rule_id" value="<{$ruleinfo['rule']['id']}>">
				
				<table> 
					<tr>
						<th><label for="">规则名称：</label></th>
						<td>
							<input type='text' name="title" class='form-control' value="<{$ruleinfo['rule']['name']}>" style="width: 320px;" />
						</td>
					</tr>
					<tr>
						<th><label for="">关键字：</label></th>
						<td>
							<div class="keyword-box" style="height:47px">
								<div class="keyword-input">
									<input type="text" class='form-control' name="keywords" id="keywords" value="" placeholder="请输入关键字" />
									<i class="btn btn-default glyphicon glyphicon-plus" id="keyword-plus"></i>
								</div>
								<div id="keyword-list">
									<notempty name="ruleinfo['keyword']">
									<volist name="ruleinfo['keyword']" id="item">
										<span class="keyword-item">
											<{$item['content']}>
											<input type="hidden"  class="form-control keyword-name" name="keyword-name[<{$item['id']}>]" value="<{$item['content']}>" />
											<input type="hidden" name="keyword-type[<{$item['id']}>]" value="1" />
											<i class="glyphicon glyphicon-remove" onclick="removeKeyword(this)"></i>
										</span>
									</volist>
									</notempty>
								</div>
								<div class="clear"></div>
							</div>
						</td>
					</tr>
				</table>
			
				<!-- 图文预览 -->
				<div class="marboxleft" style="margin-top:25px;width:100%" >
					<div class="postcontent" style="margin-left:50px;">
						<!-- <div class="arrow"></div> -->
						<span class='product' editid="one" >
							<table class="pro ruletablebox" style="border-radius:0px;">
								<tr>
									<th><label for="">标题：</label></th>
									<td>
										<input type="text" id="newstitle" name="newstitle" class="form-control"  value="<{$result[0]['title']}>" style="width:350px">
									</td>
								</tr>
								<tr>
									<th><label for="">封面：</label></th>
									<td>
										<div class="upload-file-box" style="width:350px">
											<div class="radio col-sm-5">
												<a class="btn btn-default" id="uploadify">上传图片</a> <span style="margin-top:10px;float:left;color:#999">（仅允许上传1MB以内的图片）</span>
											</div>
											<div id="upload-file-view" class="OneImageBox upload-view">
												<div id="showimg">
											
												<if condition="!empty($result[0]['thumb'])">
													<div style="width:100px;height:100px;border:1px solid #ccc;overflow:hidden;float:left;">
														<img src="<{$result[0]['thumb']}>" style="width:100px;height:100px;float:left;margin:0 auto;padding:5px;">
														<div onclick="removeImg();" style="height:30px;width:100%;background:#000;opacity:.6;text-align:center;z-index:3;position:relative;bottom:30px;color:#fff;line-height:30px;float:left;cursor:pointer;">删除</div>
													</div>
												</if>
												</div>
												<input type="hidden" id="newspicture" name="newspicture" value="<{$result[0]['thumb']}>"/>
											</div>
										</div>
									</td>
								</tr>
								
								<tr>
									<th><label for="">描述：</label></th>
									<td>
										<input type='text' id="newsdescription" name="newsdescription" style="width:350px" class="form-control" value="<{$result[0]['description']}>" />
									</td>
								</tr>
								<tr>
									<th><label for="">内容：</label></th>
									<td>
										<textarea id="newscontent" name="newscontent" class="richtext-clone"  cols="70" style="width:300px;height:300px"><{$result[0]['content']}></textarea>
										<{:A('Admin/Editor')->buildEditor('newscontent');}>
									</td>
								</tr>
								<tr>
									<th><label for="">来源：</label></th>
									<td class='width' >
										<input type="text" id="newsurl"  class="form-control input0" placeholder=""  <if condition = "!empty($result[0]['url'])">value="<{$result[0]['url']}>"<else />value=""</if> style="width:350px" name="newsurl" >
									</td>
								</tr>
							</table>
						</span>
					</div>
				</div>
				
				<div class="clear"></div>
				<div style="text-align:center">
					<button type="submit" onclick='addKeyword();return checkkeyword();'  class="btn btn-danger " name="submit" value="保存" style="width:150px;margin-bottom:20px"/>保存</button>
					<input type='hidden' name='delnews'  id='delnews' value=''/>
				</div>

				
			</form>
		</div>
	</div>
</div>
<script>

	$(function(){
         window.onload=function(){
             $("#one .appmsg_edit_mask a").click();
         }
		
         $(document).click(function(){
             //view();
         });
        $(".cover_appmsg_item").mouseover(function(){
            $(this).find(".appmsg_edit_mask").show();
        }).mouseout(function(){
           $(this).find(".appmsg_edit_mask").hide();
        });

        $(".appmsg_item").on('mouseover mouseout',function(e){
            if(e.type == 'mouseover'){
                $(this).find(".appmsg_edit_mask").show();
            }else if(e.type == 'mouseout'){
                $(this).find(".appmsg_edit_mask").hide();
            }
        });


		$(".add-kw-button").click(function(){
			$(".rulekeylist").append("<span><input type='text' class='span4' value='' name='keyword-name-new[]'/><a class='close'>×</a><input type='hidden'name='keyword-type-new[]' value='1'/></span>");
		});
		
		$(".close").on('click',function(){
			var i =0;
			i = $(".rulekeylist span").length;
			if(i == 1){
				message('关键字最少有一个',null,'error');
				return false;
			}
			$(this).parent('span').remove();
		});


		//添加多图文
		$(".add_field_toggle").click(function(){
			var html="",i=0;
			i=$(".appmsg_item").length;
			var numc=i;
			if(numc >=9){
				message('多图文回复最多9条',null,'error');
				return false;
			}
            html +='<div id="newsappmsg'+numc+'"  class="appmsg_item js_appmsg_item  has_thumb">';
            html+='<img class="js_appmsg_thumb appmsg_thumb" src="__PUBLIC__/Application/images/notimage.jpg">';
            html+='<span class="appmsg_title"><a onclick="return false;" href="javascript:void(0);" target="_blank">标题</a></span>';
            html+='<div class="appmsg_edit_mask">';
            html+='<a class="" onclick="appmsgnewsedit(this)" href="javascript:void(0);"><i class="glyphicon glyphicon-edit"></i></a>';
            html+='<a class="" onclick="appmsgnewsdelete(this)" href="javascript:void(0);"><i class="glyphicon glyphicon-remove"></i></a>';
            html+='</div>';
            html+='<input type="hidden" class="newstitle" name="news-title-new[news-wrap-item-<{$itmeid}>][]" />';
            html+='<input type="hidden" class="newspic" name="news-picture-new[news-wrap-item-<{$itmeid}>][]" />';
            html+='<input type="hidden" class="newsdescription" name="news-description-new[news-wrap-item-<{$itmeid}>][]" />';
			html+='<input type="hidden" class="is_picture" name="news-is-picture-new[news-wrap-item-<{$itmeid}>][<{$itmeid}>]"   />';
            html+='<textarea style="display:none"   class="newscontent" name="news-content-new[news-wrap-item-<{$itmeid}>][]"></textarea>';
            html+='<input type="hidden" class="newsurl" name="news-url-new[news-wrap-item-<{$itmeid}>][]" />';
            html+='</div>';

           
            $(this).parent().before(html);

             $(".appmsg_item").on('mouseover mouseout',function(e){
                if(e.type == 'mouseover'){
                    $(this).find(".appmsg_edit_mask").show();
                }else if(e.type == 'mouseout'){
                    $(this).find(".appmsg_edit_mask").hide();
                }
            });
		});

	});

   

	function onclick_picture(){
		var editid=$(".product").attr('editid');
		if($('#is-picture').prop('checked') == true){
			$("#"+editid).find(".is_picture").val('on');
		}else{
			$("#"+editid).find(".is_picture").val('');
		}
	
	}
	
	
 
    //删除
    function appmsgnewsdelete(obj){
        var cid=$(obj).parents(".appmsg_item").attr('cid');
        if(cid != undefined){
            var del=$("#delnews").val();
            $("#delnews").val(del+","+cid);
        }
        $(obj).parents(".appmsg_item").remove();

        $("#one .appmsg_edit_mask a").click();
    }
	
	//全局应用中心调用ajax提交
	function postrule(curform){
	
		var title = $('input[name="title"]').val();
		var newstitle = $('input[name="newstitle"]').val();
		var newspicture = $('input[name="newspicture"]').val();
		var url = $('input[name="newsurl"]').val();
		
		if(!title){
			layer.alert('请输入规则名称');
			return false;
		}
		
		if(!newstitle){
			layer.alert('请输入标题');
			return false;
		}
		
		if(!newspicture){
			layer.alert('请上传图片');
			return false;
		}
		
		if(!title){
			layer.alert('请输入链接');
			return false;
		}
		
			var url = '';
			$.post(url,$(curform).serializeArray(),function(data){
			
				if(data.status == '1'){
					//layer.alert(data.info,{icon: 1});
					window.location.href = "<{:U('News/Rule/RuleDisplay',array('k'=>9,'sk'=>2))}>";
				}else{
					layer.alert(data.info,{icon: 2});
				}
			});
		return false;
	}
	
	//移除图片
	function removeImg(){
		$("#showimg").html('');
		$("#newspicture").val('');
	}
	
	
	// 文件上传
	$("#uploadify").uploadify({
	//	'formData': {"uptype":"cate"},
		'swf'           : '/Public/js/uploadify/uploadify.swf',
		'uploader'      : "<?php echo U('Admin/Gallery/uploadImg');?>",
		'fileTypeExts'	: '*.jpg;*.png;*.gif',
		'width'			: 90,
		'buttonText' : '<a class="btn btn-default" id="uploadify">上传图片</a>',
		'hideButton' : true,
		'multi': false,
		'fileObjName' : 'imgFile',
		'fileSizeLimit' : '1MB',
		'onUploadError' : function(back) {
			
		},
		'onUploadStart' : function(file) {

    	},
		'onUploadSuccess' : function(file,data,response) {
			var r = jQuery.parseJSON(data);
			if(r.error == 0){
				var htm = '<div style="width:100px;height:100px;border:1px solid #ccc;overflow:hidden;float:left;">';
				htm += '<img src="/'+r.imgUrl+'" style="width:100px;height:100px;float:left;margin:0 auto;padding:5px;">';
				htm += '<div onclick="removeImg();" style="height:30px;width:100%;background:#000;opacity:.6;text-align:center;z-index:3;position:relative;bottom:30px;color:#fff;line-height:30px;float:left;cursor:pointer;">删除</div>';
				htm += '</div>';
				$('#showimg').html('');
				$("#showimg").append(htm);
				$("#newspicture").val("/"+r.imgUrl+"");
			}
		},
	
	});
	
</script>
<style>
@media screen and (min-width: 1200px) { 
.main-mid>.content{min-height:529px;background:#fff;padding: 10px 35px 80px 35px;} 
} 
@media screen and (max-width: 1100px) { 
.main-mid>.content{min-height:529px;background:#fff;padding: 10px 0px 80px 35px;} 
}

@media screen and (min-width: 1200px) { 
	.appmsg {
		/*position: relative;*/
		overflow: hidden;
		margin-bottom: 20px;
		border: 1px solid #e7e7eb;
		background-color: #fff;
		color: #8d8d8d;
		width:300px;
		float:left;
	}
} 
@media screen and (max-width: 1100px) { 
	.appmsg {
	/*position: relative;*/
	overflow: hidden;
	margin-bottom: 20px;
	border: 1px solid #e7e7eb;
	background-color: #fff;
	color: #8d8d8d;
	width:30%;
	float:left;
	}
}
input.span5{
	width:450px
}
.appmsg_thumb_wrp img {
	width:100%;
	height:100%
}
.mainCon table, #mainCon table th, #mainCon table td{
	border:0px;
}
</style>
